//uni的平台能力相关
export class UniPlatform {
    /**
     * 获取 openId
     * @returns {Promise<*|string>}
     */
    static async getCode() {
        let [err, res] = await uni.login({
            provider: 'weixin',
            onlyAuthorize: true,
        })
        if (err !== null) {
            throw Error("获取code失败")
        }
        let {code} = res
        return code
    }
    //扫码
    static async  scanCode(config={}){
        try {
            let [err,res] = await uni.scanCode(config)
            return res.result
        } catch (e) {
            console.log("扫码失败",e)
        }
    }
    //打电话
    static async callPhone(phoneNumber) {
        try {
            let flag = await ModalUtils.showModalPromise(phoneNumber, {
                title: '是否拨打电话'
            })
            if (flag) {
                uni.makePhoneCall({
                    phoneNumber,
                    success() {
                        console.log("调用成功")
                    },
                    fail() {
                        console.log("调用失败")
                    }
                })
            }
        } catch (e) {
            console.log(e)
        }
    }
}
